package com.leslie.springboottest.util;

import com.leslie.springboottest.data.PersonResponse;
import com.leslie.springboottest.enums.PersonResponseEnum;
import com.leslie.springboottest.excption.PersonException;

public class PersonResponseUtil {
    public static PersonResponse success(Object object) {
        PersonResponse personResponse = new PersonResponse();
        personResponse.setCode(PersonResponseEnum.SUCCESS.getCode());
        personResponse.setMessage(PersonResponseEnum.SUCCESS.getMessage());
        personResponse.setData(object);
        return personResponse;
    }

    public static PersonResponse error(Integer code, String message){
        PersonResponse personResponse = new PersonResponse();
        personResponse.setCode(code);
        personResponse.setMessage(message);
        return personResponse;
    }

    public static PersonResponse error(PersonResponseEnum personResponseEnum){
        PersonResponse personResponse = new PersonResponse();
        personResponse.setCode(personResponseEnum.getCode());
        personResponse.setMessage(personResponseEnum.getMessage());
        return personResponse;
    }

    public static PersonResponse error(PersonException personException){
        PersonResponse personResponse = new PersonResponse();
        personResponse.setCode(personException.getCode());
        personResponse.setMessage(personException.getMessage());
        return personResponse;
    }
}
